﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class admin_Pro_Operation : System.Web.UI.Page
{
    string sql;
    protected void Page_Load(object sender, EventArgs e)
    {
        AdminCs.CheckLoginState();
        if (!this.IsPostBack)
        {

            bind_d();
            Areabig();

           
            if (Request.QueryString["cp"] == "edit")　//显示文本信息
            {
                pro_txt();
                bind_t1();
                bind_t2();

                bind_a1();
                bind_a2();
                bind_a3();
            }
            else if (Request.QueryString["cp"] == "del")　//删除信息
            {
                del_pro();
            }
        }
    }
    #region  地区 分类
    public void Areabig()//地区大类
    {
        sql = "select * from Area where oneid<>0 and twoid=0 and threeid=0 order by sort";
        DataTable dt = Class1.ExecSel(sql);
        Ddl_AreaOne.DataSource = dt;
        Ddl_AreaOne.DataTextField = "areaname";
        Ddl_AreaOne.DataValueField = "oneid";
        Ddl_AreaOne.DataBind();
    }
    protected void Ddl_AreaOne_SelectedIndexChanged(object sender, EventArgs e)
    {
        Ddl_AreaTwo.Items.Clear();
        Ddl_AreaTwo.Items.Add(new ListItem("全部", "0"));
        Ddl_AreaThree.Items.Clear();
        Ddl_AreaThree.Items.Add(new ListItem("全部", "0"));

        sql = "select * from Area where twoid<>0 and threeid=0 and oneid=" + Ddl_AreaOne.SelectedValue + " order by sort";
        DataTable dt = Class1.ExecSel(sql);
        Ddl_AreaTwo.DataSource = dt;
        Ddl_AreaTwo.DataTextField = "areaname";
        Ddl_AreaTwo.DataValueField = "twoid";
        Ddl_AreaTwo.DataBind();
    }
    protected void Ddl_AreaTwo_SelectedIndexChanged(object sender, EventArgs e)
    {
        Ddl_AreaThree.Items.Clear();
        Ddl_AreaThree.Items.Add(new ListItem("全部", "0"));

        sql = "select * from Area where threeid<>0 and oneid=" + Ddl_AreaOne.SelectedValue;
        sql += " and twoid=" + Ddl_AreaTwo.SelectedValue + " order by sort";
        DataTable dt = Class1.ExecSel(sql);
        Ddl_AreaThree.DataSource = dt;
        Ddl_AreaThree.DataTextField = "areaname";
        Ddl_AreaThree.DataValueField = "threeid";
        Ddl_AreaThree.DataBind();
    }

    public void bind_d()//绑定大类
    {
        sql = "select * from PsClass where Menu_Level=1";
        DataTable dt = Class1.ExecSel(sql);
        this.DropDownList1.DataSource = dt;
        this.DropDownList1.DataTextField = "Menu_Name";
        this.DropDownList1.DataValueField = "Menu_ID";
        this.DropDownList1.DataBind();
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string ID = this.DropDownList1.SelectedValue;

        DropDownList2.Items.Clear();
        DropDownList2.Items.Add(new ListItem("全部", "0"));

        sql = "select * from PsClass where Menu_Level=2 and Menu_ParentLevel=" + ID;
        DataTable dt = Class1.ExecSel(sql);
        this.DropDownList2.DataSource = dt;
        this.DropDownList2.DataTextField = "Menu_Name";
        this.DropDownList2.DataValueField = "Menu_ID";
        this.DropDownList2.DataBind();

    }

    #endregion

    #region 上传图片
    protected void UpImg_Click(object sender, EventArgs e)//上传图片
    {
        if (FileUpload1.PostedFile.ContentLength < 500000)//100000为100K
        {

            string fileFullname = this.FileUpload1.FileName;
            string dataName = DateTime.Now.ToString("yyyyMMddhhmmss");
            string fileName = fileFullname.Substring(fileFullname.LastIndexOf("\\") + 1);
            string type = fileFullname.Substring(fileFullname.LastIndexOf(".") + 1);
            if (type == "bmp" || type == "jpg" || type == "gif" || type == "JPG" || type == "BMP" || type == "GIF")
            {
                this.FileUpload1.SaveAs(Server.MapPath("../Images") + "\\" + dataName + "." + type);
                string ProImg = "Images/" + dataName + "." + type;
                this.txtProImg.Text = "Images/" + dataName + "." + type;
            }
            else
            {
                Response.Write("<script language='javascript'>alert('支持格式：|jpg|gif|bmp|');</script>");
            }
        }
        else
        {
            Response.Write("<script language='javascript'>alert('你的图片已经超过500K的大小！');</script>");
        }
    }
    #endregion

    #region 执行添加
    public void pro_add()//执行添加
    {
        string Ddl1 = DropDownList1.SelectedValue;
        string Ddl2 = DropDownList2.SelectedValue;

        string Ddl4 = Ddl_AreaOne.SelectedValue;
        string Ddl5 = Ddl_AreaTwo.SelectedValue;
        string Ddl6 = Ddl_AreaThree.SelectedValue;

        string AreaA = Ddl_AreaOne.SelectedItem.Text;
        string AreaB = Ddl_AreaTwo.SelectedItem.Text;
        string AreaC = Ddl_AreaThree.SelectedItem.Text;

        string Type = DropDownList4.SelectedItem.Text;
        string Title = TextBox1.Text;
        string ProImg = txtProImg.Text;
        string Amount = TextBox2.Text;
        string Packing = TextBox3.Text;
        string Prices = TextBox4.Text;
        string Specifications = TextBox5.Text;
        int Period = Convert.ToInt32(DropDownList5.SelectedValue);
        string Content = ftbContent.Text.Trim();
        string Contacts = TextBox7.Text;
        string Tel = TextBox8.Text;
        string Phone = TextBox9.Text;
        string Fax = TextBox10.Text;
        string Email = TextBox6.Text;
        string Website = TextBox11.Text;
        string Address = TextBox12.Text;
        DateTime Time = DateTime.Now;


        if (Ddl1 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择一级分类！');", true);
            return;
        }
        else if (Ddl2 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择二级分类！');", true);
            return;
        }
        else if (Ddl4 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择省分类！');", true);
            return;
        }
        else if (Ddl5 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择市分类！');", true);
            return;
        }
        else if (Ddl6 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择市区分类！');", true);
            return;
        }
        else if (Title == "")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('标题不能为空！');", true);
            return;
        }
        else if (Period == 0)
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请填写有效期！');", true);
            return;
        }

        else if (Title.Length > 100)
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('标题不能大于100个字！');", true);
            return;
        }
        else if (Type == "请选择")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择类型！');", true);
            return;
        }
        else
        {

            string sql = "insert into Delivery(p_b_ID,p_z_ID,p_AreaOne,p_AreaTwo,p_AreaThree,p_Type,p_Title,p_ProImg,p_Amount,p_Packing,p_Prices,p_Specifications,p_EndTime,p_Content,p_Contacts,p_Tel,p_Phone,p_Fax,p_Email,p_Website,p_Address,p_Time,p_AreaA,p_AreaB,p_AreaC)";
            sql += "values(" + Ddl1 + "," + Ddl2 + "," + Ddl4 + "," + Ddl5 + "," + Ddl6 + ",'" + Type + "','" + Title + "','" + ProImg + "'," + Amount + ",'" + Packing + "','" + Prices + "','" + Specifications + "','" + Period + "','" + Content + "','" + Contacts + "'," + Tel + "," + Phone + "," + Fax + ",'" + Email + "','" + Website + "','" + Address + "','" + Time + "','" + AreaA + "','" + AreaB + "','" + AreaC + "')";
            Class1.ExecSql(sql);
            Class1.AlertShow("添加成功！", "Pro_Operation.aspx?cp=add");
        }
    }
    #endregion

    #region 显示修改的文本信息
    public void pro_txt()//显示修改的文本信息
    {
        int id = int.Parse(Request.QueryString["ID"]);
        DataTable dt = Class1.ExecSel("select * from Delivery where p_ID='" + id + "'");
        TextBox1.Text = Convert.ToString(dt.Rows[0]["p_Title"]);
        txtProImg.Text = Convert.ToString(dt.Rows[0]["p_ProImg"]);
        TextBox2.Text = Convert.ToString(dt.Rows[0]["p_Amount"].ToString());
        TextBox3.Text = Convert.ToString(dt.Rows[0]["p_Packing"].ToString());
        TextBox4.Text = Convert.ToString(dt.Rows[0]["p_Prices"].ToString());
        TextBox5.Text = Convert.ToString(dt.Rows[0]["p_Specifications"].ToString());



        if (dt.Rows[0]["p_EndTime"].ToString().Trim() == "7")
        {
            this.DropDownList5.Items[0].Selected = false;
            this.DropDownList5.Items[1].Selected = true;
            this.DropDownList5.Items[2].Selected = false;
            this.DropDownList5.Items[3].Selected = false;
            this.DropDownList5.Items[4].Selected = false;
            this.DropDownList5.Items[5].Selected = false;
            this.DropDownList5.Items[6].Selected = false;
            this.DropDownList5.Items[7].Selected = false;
        }
        else if (dt.Rows[0]["p_EndTime"].ToString().Trim() == "15")
        {
            this.DropDownList5.Items[0].Selected = false;
            this.DropDownList5.Items[1].Selected = false;
            this.DropDownList5.Items[2].Selected = true;
            this.DropDownList5.Items[3].Selected = false;
            this.DropDownList5.Items[4].Selected = false;
            this.DropDownList5.Items[5].Selected = false;
            this.DropDownList5.Items[6].Selected = false;
            this.DropDownList5.Items[7].Selected = false;
        }
        else if (dt.Rows[0]["p_EndTime"].ToString().Trim() == "30")
        {
            this.DropDownList5.Items[0].Selected = false;
            this.DropDownList5.Items[1].Selected = false;
            this.DropDownList5.Items[2].Selected = false;
            this.DropDownList5.Items[3].Selected = true;
            this.DropDownList5.Items[4].Selected = false;
            this.DropDownList5.Items[5].Selected = false;
            this.DropDownList5.Items[6].Selected = false;
            this.DropDownList5.Items[7].Selected = false;
        }
        else if (dt.Rows[0]["p_EndTime"].ToString().Trim() == "60")
        {
            this.DropDownList5.Items[0].Selected = false;
            this.DropDownList5.Items[1].Selected = false;
            this.DropDownList5.Items[2].Selected = false;
            this.DropDownList5.Items[3].Selected = false;
            this.DropDownList5.Items[4].Selected = true;
            this.DropDownList5.Items[5].Selected = false;
            this.DropDownList5.Items[6].Selected = false;
            this.DropDownList5.Items[7].Selected = false;
        }
        else if (dt.Rows[0]["p_EndTime"].ToString().Trim() == "90")
        {
            this.DropDownList5.Items[0].Selected = false;
            this.DropDownList5.Items[1].Selected = false;
            this.DropDownList5.Items[2].Selected = false;
            this.DropDownList5.Items[3].Selected = false;
            this.DropDownList5.Items[4].Selected = false;
            this.DropDownList5.Items[5].Selected = true;
            this.DropDownList5.Items[6].Selected = false;
            this.DropDownList5.Items[7].Selected = false;
        }
        else if (dt.Rows[0]["p_EndTime"].ToString().Trim() == "180")
        {
            this.DropDownList5.Items[0].Selected = false;
            this.DropDownList5.Items[1].Selected = false;
            this.DropDownList5.Items[2].Selected = false;
            this.DropDownList5.Items[3].Selected = false;
            this.DropDownList5.Items[4].Selected = false;
            this.DropDownList5.Items[5].Selected = false;
            this.DropDownList5.Items[6].Selected = true;
            this.DropDownList5.Items[7].Selected = false;
        }
        else if (dt.Rows[0]["p_EndTime"].ToString().Trim() == "360")
        {
            this.DropDownList5.Items[0].Selected = false;
            this.DropDownList5.Items[1].Selected = false;
            this.DropDownList5.Items[2].Selected = false;
            this.DropDownList5.Items[3].Selected = false;
            this.DropDownList5.Items[4].Selected = false;
            this.DropDownList5.Items[5].Selected = false;
            this.DropDownList5.Items[6].Selected = false;
            this.DropDownList5.Items[7].Selected = true;
        }


        ftbContent.Text = Convert.ToString(dt.Rows[0]["p_Content"].ToString());
        TextBox7.Text = Convert.ToString(dt.Rows[0]["p_Contacts"].ToString());
        TextBox8.Text = Convert.ToString(dt.Rows[0]["p_Tel"].ToString());
        TextBox9.Text = Convert.ToString(dt.Rows[0]["p_Phone"].ToString());
        TextBox10.Text = Convert.ToString(dt.Rows[0]["p_Fax"].ToString());
        TextBox6.Text = Convert.ToString(dt.Rows[0]["p_Email"].ToString());
        TextBox11.Text = Convert.ToString(dt.Rows[0]["p_Website"].ToString());
        TextBox12.Text = Convert.ToString(dt.Rows[0]["p_Address"].ToString());

        if (dt.Rows[0]["p_Type"].ToString().Trim() == "请选择")
        {
            this.DropDownList4.Items[0].Selected = true;
            this.DropDownList4.Items[1].Selected = false;
            this.DropDownList4.Items[2].Selected = false;
            this.DropDownList4.Items[3].Selected = false;
            this.DropDownList4.Items[4].Selected = false;
            this.DropDownList4.Items[5].Selected = false;
            this.DropDownList4.Items[6].Selected = false;
            this.DropDownList4.Items[7].Selected = false;
            this.DropDownList4.Items[8].Selected = false;
        }
        if (dt.Rows[0]["p_Type"].ToString().Trim() == "供应")
        {
            this.DropDownList4.Items[0].Selected = false;
            this.DropDownList4.Items[1].Selected = true;
            this.DropDownList4.Items[2].Selected = false;
            this.DropDownList4.Items[3].Selected = false;
            this.DropDownList4.Items[4].Selected = false;
            this.DropDownList4.Items[5].Selected = false;
            this.DropDownList4.Items[6].Selected = false;
            this.DropDownList4.Items[7].Selected = false;
            this.DropDownList4.Items[8].Selected = false;
        }
        if (dt.Rows[0]["p_Type"].ToString().Trim() == "采购")
        {
            this.DropDownList4.Items[0].Selected = false;
            this.DropDownList4.Items[1].Selected = false;
            this.DropDownList4.Items[2].Selected = true;
            this.DropDownList4.Items[3].Selected = false;
            this.DropDownList4.Items[4].Selected = false;
            this.DropDownList4.Items[5].Selected = false;
            this.DropDownList4.Items[6].Selected = false;
            this.DropDownList4.Items[7].Selected = false;
            this.DropDownList4.Items[8].Selected = false;
        }
        if (dt.Rows[0]["p_Type"].ToString().Trim() == "代理")
        {
            this.DropDownList4.Items[0].Selected = false;
            this.DropDownList4.Items[1].Selected = false;
            this.DropDownList4.Items[2].Selected = false;
            this.DropDownList4.Items[3].Selected = true;
            this.DropDownList4.Items[4].Selected = false;
            this.DropDownList4.Items[5].Selected = false;
            this.DropDownList4.Items[6].Selected = false;
            this.DropDownList4.Items[7].Selected = false;
            this.DropDownList4.Items[8].Selected = false;
        }
        if (dt.Rows[0]["p_Type"].ToString().Trim() == "合作")
        {
            this.DropDownList4.Items[0].Selected = false;
            this.DropDownList4.Items[1].Selected = false;
            this.DropDownList4.Items[2].Selected = false;
            this.DropDownList4.Items[3].Selected = false;
            this.DropDownList4.Items[4].Selected = true;
            this.DropDownList4.Items[5].Selected = false;
            this.DropDownList4.Items[6].Selected = false;
            this.DropDownList4.Items[7].Selected = false;
            this.DropDownList4.Items[8].Selected = false;
        }
        if (dt.Rows[0]["p_Type"].ToString().Trim() == "招投标")
        {
            this.DropDownList4.Items[0].Selected = false;
            this.DropDownList4.Items[1].Selected = false;
            this.DropDownList4.Items[2].Selected = false;
            this.DropDownList4.Items[3].Selected = false;
            this.DropDownList4.Items[4].Selected = false;
            this.DropDownList4.Items[5].Selected = true;
            this.DropDownList4.Items[6].Selected = false;
            this.DropDownList4.Items[7].Selected = false;
            this.DropDownList4.Items[8].Selected = false;
        }
        if (dt.Rows[0]["p_Type"].ToString().Trim() == "融资")
        {
            this.DropDownList4.Items[0].Selected = false;
            this.DropDownList4.Items[1].Selected = false;
            this.DropDownList4.Items[2].Selected = false;
            this.DropDownList4.Items[3].Selected = false;
            this.DropDownList4.Items[4].Selected = false;
            this.DropDownList4.Items[5].Selected = false;
            this.DropDownList4.Items[6].Selected = true;
            this.DropDownList4.Items[7].Selected = false;
            this.DropDownList4.Items[8].Selected = false;
        }
        if (dt.Rows[0]["p_Type"].ToString().Trim() == "厂店租售")
        {
            this.DropDownList4.Items[0].Selected = false;
            this.DropDownList4.Items[1].Selected = false;
            this.DropDownList4.Items[2].Selected = false;
            this.DropDownList4.Items[3].Selected = false;
            this.DropDownList4.Items[4].Selected = false;
            this.DropDownList4.Items[5].Selected = false;
            this.DropDownList4.Items[6].Selected = false;
            this.DropDownList4.Items[7].Selected = true;
            this.DropDownList4.Items[8].Selected = false;
        }
        if (dt.Rows[0]["p_Type"].ToString().Trim() == "其它")
        {
            this.DropDownList4.Items[0].Selected = false;
            this.DropDownList4.Items[1].Selected = false;
            this.DropDownList4.Items[2].Selected = false;
            this.DropDownList4.Items[3].Selected = false;
            this.DropDownList4.Items[4].Selected = false;
            this.DropDownList4.Items[5].Selected = false;
            this.DropDownList4.Items[6].Selected = false;
            this.DropDownList4.Items[7].Selected = false;
            this.DropDownList4.Items[8].Selected = true;
        }

    }
    #endregion

    #region　城市显示
    public void bind_a1()//绑定省
    {
        int id = int.Parse(Request.QueryString["ID"]);
        DataTable dt = Class1.ExecSel("select * from Delivery where p_ID=" + id + "");
        Session["dl"] = Convert.ToString(dt.Rows[0]["p_AreaOne"].ToString());

        sql = "select * from Area where oneid<>0 and twoid=0 and threeid=0 order by sort";
        DataTable dt2 = Class1.ExecSel(sql);
        this.Ddl_AreaOne.DataSource = dt2;
        this.Ddl_AreaOne.DataTextField = "areaname";
        this.Ddl_AreaOne.DataValueField = "oneid";
        this.Ddl_AreaOne.SelectedValue = Session["dl"].ToString();
        this.Ddl_AreaOne.DataBind();
    }
    public void bind_a2()//绑定市
    {
        int id = int.Parse(Request.QueryString["ID"]);
        DataTable dt = Class1.ExecSel("select * from Delivery where p_ID=" + id + "");
        Session["zl"] = Convert.ToString(dt.Rows[0]["p_AreaTwo"].ToString());

        sql = "select * from Area where twoid<>0 and threeid=0 and oneid=" + Ddl_AreaOne.SelectedValue + " order by sort";
        DataTable dt2 = Class1.ExecSel(sql);
        this.Ddl_AreaTwo.DataSource = dt2;
        this.Ddl_AreaTwo.DataTextField = "areaname";
        this.Ddl_AreaTwo.DataValueField = "twoid";
        this.Ddl_AreaTwo.SelectedValue = Session["zl"].ToString();
        this.Ddl_AreaTwo.DataBind();
    }
    public void bind_a3()//绑定城市
    {
        int id = int.Parse(Request.QueryString["ID"]);
        DataTable dt = Class1.ExecSel("select * from Delivery where p_ID=" + id + "");
        Session["xl"] = Convert.ToString(dt.Rows[0]["p_AreaThree"].ToString());

        sql = "select * from Area where threeid<>0 and oneid=" + Ddl_AreaOne.SelectedValue;
        sql += " and twoid=" + Ddl_AreaTwo.SelectedValue + " order by sort";
        DataTable dt2 = Class1.ExecSel(sql);
        this.Ddl_AreaThree.DataSource = dt2;
        this.Ddl_AreaThree.DataTextField = "areaname";
        this.Ddl_AreaThree.DataValueField = "threeid";
        this.Ddl_AreaThree.SelectedValue = Session["xl"].ToString();
        this.Ddl_AreaThree.DataBind();
    }

    #endregion

    #region 分类显示
    public void bind_t1()//绑定大类
    {
        int id = int.Parse(Request.QueryString["ID"]);
        DataTable dt = Class1.ExecSel("select * from Delivery where p_ID=" + id + "");
        Session["dl"] = Convert.ToString(dt.Rows[0]["p_b_ID"].ToString());

        sql = "select * from PsClass where Menu_Level=1";
        DataTable dt2 = Class1.ExecSel(sql);
        this.DropDownList1.DataSource = dt2;
        this.DropDownList1.DataTextField = "Menu_Name";
        this.DropDownList1.DataValueField = "Menu_ID";
        this.DropDownList1.SelectedValue = Session["dl"].ToString();
        this.DropDownList1.DataBind();
    }
    public void bind_t2()//绑定中类
    {
        int id = int.Parse(Request.QueryString["ID"]);
        DataTable dt = Class1.ExecSel("select * from Delivery where p_ID=" + id + "");
        Session["zl"] = Convert.ToString(dt.Rows[0]["p_z_ID"].ToString());

        sql = "select * from PsClass where  Menu_ParentLevel=" + this.DropDownList1.SelectedValue;
        DataTable dt2 = Class1.ExecSel(sql);
        this.DropDownList2.DataSource = dt2;
        this.DropDownList2.DataTextField = "Menu_Name";
        this.DropDownList2.DataValueField = "Menu_ID";
        this.DropDownList2.SelectedValue = Session["zl"].ToString();
        this.DropDownList2.DataBind();
    }

#endregion

    #region 修改信息
    public void pro_edit()//修改信息
    {
        int id = int.Parse(Request.QueryString["ID"]);
        string Ddl1 = DropDownList1.SelectedValue;
        string Ddl2 = DropDownList2.SelectedValue;
        string Ddl4 = Ddl_AreaOne.SelectedValue;
        string Ddl5 = Ddl_AreaTwo.SelectedValue;
        string Ddl6 = Ddl_AreaThree.SelectedValue;
        string Type = DropDownList4.SelectedItem.Text;
        string Title = TextBox1.Text;
        string ProImg = this.txtProImg.Text;
        string Amount = TextBox2.Text;
        string Packing = TextBox3.Text;
        string Prices = TextBox4.Text;
        string Specifications = TextBox5.Text;
        int Period = Convert.ToInt32(DropDownList5.SelectedValue);
        string Content = ftbContent.Text.Trim();
        string Contacts = TextBox7.Text;
        string Tel = TextBox8.Text;
        string Phone = TextBox9.Text;
        string Fax = TextBox10.Text;
        string Email = TextBox6.Text;
        string Website = TextBox11.Text;
        string Address = TextBox12.Text;


        if (Ddl1 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择一级分类！');", true);
            return;
        }
        else if (Ddl2 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择二级分类！');", true);
            return;
        }
        else if (Ddl4 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择省分类！');", true);
            return;
        }
        else if (Ddl5 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择市分类！');", true);
            return;
        }
        else if (Ddl6 == "0")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择市区分类！');", true);
            return;
        }
        else if (Period == 0)
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请填写有效期！');", true);
            return;
        }
        else if (Title == "")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('标题不能为空！');", true);
            return;
        }
        else if (Title.Length > 100)
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('标题不能大于100个字！');", true);
            return;
        }
        else if (Type == "请选择")
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "TestAlert", "alert('请选择类型！');", true);
            return;
        }

        else
        {
            string sql = ("update Delivery set p_b_ID=" + Ddl1 + ",p_z_ID=" + Ddl2 + ",p_AreaOne=" + Ddl4 + ",p_AreaTwo=" + Ddl5 + ",p_AreaThree=" + Ddl6 + ",p_Type='" + Type + "',p_Title='" + Title + "',p_ProImg='" + ProImg + "',p_Amount='" + Amount + "',p_Packing='" + Packing + "',p_Prices='" + Prices + "',p_Specifications='" + Specifications + "',p_EndTime='" + Period + "',p_Content='" + Content + "',p_Contacts='" + Contacts + "',p_Tel='" + Tel + "',p_Phone='" + Phone + "',p_Fax='" + Fax + "',p_Email='" + Email + "',p_Website='" + Website + "',p_Address='" + Address + "' where p_ID=" + id + "");
            Class1.ExecSql(sql);
            Class1.AlertShow("修改成功！", "PS_Manage.aspx");
        }
    }
    #endregion

    #region 删除信息
    public void del_pro()//删除信息
    {
        int id = int.Parse(Request.QueryString["ID"]);
        string sql = "delete  Delivery where p_ID=" + id;
        Class1.ExecSql(sql);
        Class1.AlertShow("删除成功！", "PS_Manage.aspx");
    }
    #endregion

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["cp"] == "add")
        {
            pro_add();
        }
        else if (Request.QueryString["cp"] == "edit")
        {
            pro_edit();
        }
    }
    //#region 选择时间
    //protected void imgCalendar_Click(object sender, ImageClickEventArgs e)
    //{
    //    calendar.Visible = true;

    //}

    //protected void calendar_SelectionChanged(object sender, EventArgs e)
    //{
    //    txtEndTime.Text = calendar.SelectedDate.ToString("yyyy-MM-dd");
    //    calendar.Visible = false;

    //}


    //#endregion
}
